package com.xy.sdk.share;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class ShareUtil {


    // 将Drawable资源复制到内部存储并返回文件路径
    public static String getDrawableAsFile(Context context, int drawableResId, String fileName) {
        try {
            // 获取应用内部存储目录
            File file = new File(context.getFilesDir(), fileName);

            // 打开Drawable资源流
            InputStream inputStream = context.getResources().openRawResource(drawableResId);

            // 将资源写入文件
            FileOutputStream outputStream = new FileOutputStream(file);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }

            // 关闭流
            outputStream.close();
            inputStream.close();

            // 返回文件路径
            return file.getAbsolutePath();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

}
